package com.lj.infoisland.config;

import com.lj.infoisland.handler.TokenInterceptor;
import com.lj.infoisland.service.UsersService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    private final String[] excludePathPatterns = {
            "/user/register", "/user/login", "/api/hotSearch/queryByType", "/news/getNewsCategoriesList",
            "/news/getNewsList", "/news/searchNews", "/news/getHotNew", "/news/getHotNewsList", "/news/getNewsDetailById",
            "/comment/getCommentList", "/news/isLikeNews", "/news/isCollectNews", "/news/getSimilarNews", "/uploadImage", "/news/putContent"
    };
    @Resource
    private UsersService usersService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(usersService))
                .excludePathPatterns(excludePathPatterns)
                .addPathPatterns("/**");
    }
}